﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace testingIO
{
    public partial class Form1 : Form
    {
        Stemmer stemmer;
        String path;
        const int LIMIT = 10000;
        int currentDoc;
        string[] documentList;
        public Form1()
        {
            InitializeComponent();
            stemmer = new Stemmer();
            path = @"c:\reuters\";
            button3.Enabled = false;
            currentDoc = 0;
            documentList = Directory.GetFiles(path);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            textBox1.Text = File.ReadAllText(documentList[currentDoc]);
            title.Text = documentList[currentDoc];
            currentDoc++;
            DateTime end = DateTime.Now;
            textBox2.Text = "DONE";
            textBox2.AppendText((end - now).ToString());
            button3.Enabled = true;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            button3.Enabled = false;
            DateTime now = DateTime.Now;
            char[] splitters = new char[] { '`','~','!','@','#','$','%','^','&','*','(',')','_','-','+','=','{','}','[',']',';',':','\'','"','|','\\',',','<','.','>','/','?',' ' };
            string[] stopWords = new string[] { "a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"};
            int count = 0;
            textBox5.Text = count.ToString();
            foreach (string word in textBox1.Text.Split(splitters, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!stopWords.Any( x => x.ToLower().Equals(word.ToLower())))
                {
                    textBox3.AppendText(":" + stemmer.stem(word.ToLower()));
                    count++;
                    textBox5.Text = count.ToString();
                }
            }
            DateTime end = DateTime.Now;
            textBox4.Text = (end - now).ToString();
            button3.Enabled = true;
        }
    }
}
